﻿$(function () {
    // 初始化图表函数
    echarts_1();
    echarts_2();
    echarts_6();
    echarts_31();
    echarts_32();
    echarts_33();

    const cityDictionary = {
        "安庆市": "anqing",
        "亳州市": "bozhou",
        "蚌埠市": "bangbu",
        "滁州市": "chuzhou",
        "池州市": "chizhou",
        "阜阳市": "fuyang",
        "淮南市": "huainan",
        "淮北市": "huaibei",
        "黄山市": "huangshan",
        "合肥市": "hefei",
        "六安市": "liuan",
        "马鞍山市": "maanshan",
        "宿州市": "suzhou",
        "铜陵市": "tongling",
        "芜湖市": "wuhu",
        "宣城市": "xuancheng",
        "砀山县": "dangshan",
        "广德市": "guangde"
    };

    var countResult = [];
    var temp = [];

    document.getElementById('citySelect').addEventListener('change', function(event) {
    const selectedCity = event.target.value;

    if (selectedCity === 'all') {
        alert("请选择一个城市");
        return;
    }

    console.log('选择的城市为：' + selectedCity);

    if (selectedCity in cityDictionary) {
        const cityn = cityDictionary[selectedCity];
        fetch(`http://127.0.0.1:5000/api/weather/${cityn}`)
           .then(response => {
                if (!response.ok) {
                    throw new Error('网络响应失败');
                }
                return response.json();
            })
           .then(data => {
                if (data.error) {
                    alert(data.error);
                } else {
                    console.log(data);
                    countResult = [];
                    temp = [];
                    data.weather_data.forEach(day => {
                        temp.push(day.AvgTemperature);
                    });
                    console.log(data.weather_data);
                    console.log(temp);
                    countTemp(temp);
                    const result = getTempCount();
                    contLevel(temp);
                    const level = getLevel();
                    console.log(result);
                    console.log(level);
                    echarts_31(result);
                    echarts_32(level);
                    echarts_33(cityn);
                    if (data.weather_data && data.weather_data.length > 0) {
    const maxTemps = data.weather_data.map(day => day.MaxTemperature);
    const minTemps=data.weather_data.map(day=>day.MinTemperature)
    const avgTemps=data.weather_data.map(day=>day.AvgTemperature)
    const arr = Object.values(avgTemps);
    console.log(typeof arr);
    console.log('所有日期的最高温度:', maxTemps);
    console.log('平均气温'+arr);
    console.log()
    echarts_4(maxTemps,minTemps);
    echarts_5(arr)
}

                }
            })
           .catch(error => {
                console.error('请求天气数据时出错：', error);
                alert("获取天气数据失败，请稍后重试！");
            });
    } else {
        alert("未找到该城市的数据！");
    }
});

    // countTemp 函数 - 根据天气数据进行分类
    function countTemp(data) {
        for (let i = 0; i < data.length; i++) {
            let averageTemperature = data[i];
            if (averageTemperature < 0) {
                countResult.push("0℃以下");
            } else if (averageTemperature >= 0 && averageTemperature <= 20) {
                countResult.push('0-20℃');
            } else if (averageTemperature > 20 && averageTemperature <= 30) {
                countResult.push('21-30℃');
            } else if (averageTemperature > 30 && averageTemperature <= 40) {
                countResult.push('31-40℃');
            } else if (averageTemperature > 40) {
                countResult.push('40℃以上');
            }
        }
        console.log("分类后的结果：", countResult);
    }

    // 获取温度分类统计结果
    function getTempCount() {
        let countObj = {
            "0℃以下": 0,
            "0-20℃": 0,
            "21-30℃": 0,
            "31-40℃": 0,
            "40℃以上": 0
        };

        countResult.forEach(tempRange => {
            if (countObj[tempRange] !== undefined) {
                countObj[tempRange]++;
            }
        });

        console.log("统计结果：", countObj);

        return [
            { value: countObj["0℃以下"], name: "0℃以下" },
            { value: countObj["0-20℃"], name: "0-20℃" },
            { value: countObj["21-30℃"], name: "21-30℃" },
            { value: countObj["31-40℃"], name: "31-40℃" },
            { value: countObj["40℃以上"], name: "40℃以上" }
        ];
    }

    var level = [];
    function contLevel(data) {
        level = [];
        for (let i = 0; i < data.length; i++) {
            let le = data[i];
            if (le < 10) {
                level.push("低温");
            } else if (le >= 10 && le <= 35) {
                level.push('正常');
            } else if (le > 35) {
                level.push('高温');
            }
        }
        console.log("分类后的结果：", level);
    }

    function getLevel() {
        let counLlevel = {
            "低温": 0,
            "正常": 0,
            "高温": 0,
        };

        level.forEach(levelRange => {
            if (counLlevel[levelRange] !== undefined) {
                counLlevel[levelRange]++;
            }
        });

        console.log("统计结果：", counLlevel);

        return [
            { value: counLlevel["低温"], name: "低温" },
            { value: counLlevel["正常"], name: "正常" },
            { value: counLlevel["高温"], name: "高温" },
        ];
    }

    let weathdata_max = [];
    let weatherdata_min = [];
    let allAvgTemperatures = []; // 用于存储所有城市的平均温度

    async function getWeatherData(city) {
        const url = `http://127.0.0.1:5000/api/weather/${city}`;
        try {
            const response = await fetch(url);
            const data = await response.json();

            if (data.error) {
                console.error(data.error);
                return null; // Handle error gracefully
            }

            const maxTemperatures = data.weather_data.map(day => day.MaxTemperature);
            const minTemperatures = data.weather_data.map(day => day.MinTemperature);
            const avgTemperatures = data.weather_data.map(day => day.AvgTemperature);

            console.log('Initializing weathdata_max and weatherdata_min');
            weathdata_max = maxTemperatures;
            weatherdata_min = minTemperatures;

            // 收集平均温度到全局数组
            allAvgTemperatures=avgTemperatures

            console.log('max', weathdata_max);
            console.log('min', weatherdata_min);
            console.log('qvg',allAvgTemperatures);

            return {
                city: data.city,
                highest_temperature: data.highest_temperature,
                lowest_temperature: data.lowest_temperature,
                weather_data: data.weather_data,
                average_temperature: data.average_temperature,
                temperature_level: data.level,
            };
        } catch (error) {
            console.error('Error fetching weather data:', error);
            return null; // Handle fetch error gracefully
        }
    }

    var highestTemperatures = [];
    var lowestTemperatures = [];
    var averageTemperatures = [];
    var cityNames = [
        'anqing', 'bozhou', 'bangbu', 'chuzhou', 'chizhou',
        'fuyang', 'huainan', 'huaibei', 'huangshan', 'hefei',
        'liuan', 'maanshan', 'suzhou', 'tongling', 'wuhu',
        'xuancheng', 'dangshan', 'guangde'
    ];

    async function fetchWeatherData() {
        for (let city of cityNames) {
            let weather = await getWeatherData(city);
            if (weather) {
                highestTemperatures.push(weather.highest_temperature);
                lowestTemperatures.push(weather.lowest_temperature);
                averageTemperatures.push(weather.average_temperature);

            }
        }

        echarts_1();
        echarts_2();
        echarts_6();
        echarts_31();
        echarts_32();
        echarts_33();


        // 将所有城市的平均温度合并为一个数组
        const flattenedAvgTemperatures = allAvgTemperatures.flat();
        echarts_4();
    }

    fetchWeatherData();


function echarts_1() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('echart1'));
       option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '5%',
            top: '20px',
            right: '5%',
            bottom: '10%',
            containLabel: true
        },
        xAxis: [{
            type: 'category',
            data: [
                '安庆市', '亳州市', '蚌埠市', '滁州市', '池州市',
                '阜阳市', '淮南市', '淮北市', '黄山市', '合肥市',
                '六安市', '马鞍山市', '宿州市', '铜陵市', '芜湖市',
                '宣城市', '砀山县', '广德市'
            ],
            axisLine: {
                show: true,
                lineStyle: {
                    color: "rgba(255,255,255,.1)",
                    width: 1,
                    type: "solid"
                },
            },
            axisTick: {
                show: false,
            },
            axisLabel: {
                interval: 0,
                rotate:45,
                show: true,
                textStyle: {
                    color: "rgba(255,255,255,.6)",
                    fontSize: '12',
                },
            },
        }],
        yAxis: [{
            type: 'value',
            axisLabel: {
                show: true,
                textStyle: {
                    color: "rgba(255,255,255,.6)",
                    fontSize: '12',
                },
            },
            axisTick: {
                show: false,
            },
            axisLine: {
                show: true,
                lineStyle: {
                    color: "rgba(255,255,255,.1)",
                    width: 1,
                    type: "solid"
                },
            },
            splitLine: {
                lineStyle: {
                    color: "rgba(255,255,255,.1)",
                }
            }
        }],
        series: [{
            type: 'bar',
            data: highestTemperatures,
            barWidth: '35%',
            barMinHeight: 1,  // 设置最小柱子高度
            itemStyle: {
                normal: {
                    color: '#2f89cf',
                    opacity: 1,
                    barBorderRadius: 5,
                }
            }
        }]
    };
      
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    }
function echarts_2() {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('echart2'));

       option = {
  //  backgroundColor: '#00265f',
    tooltip: {
        trigger: 'axis',
        axisPointer: { type: 'shadow'}
    },
    grid: {
        left: '0%',
		top:'10px',
        right: '0%',
        bottom: '4%',
       containLabel: true
    },
    xAxis: [{
        type: 'category',
      		data: [
            '安庆市', '亳州市', '蚌埠市', '滁州市', '池州市',
            '阜阳市', '淮南市', '淮北市', '黄山市', '合肥市',
            '六安市', '马鞍山市', '宿州市', '铜陵市', '芜湖市',
            '宣城市', '砀山县', '广德市'
        ],
        axisLine: {
            show: true,
         lineStyle: {
                color: "rgba(255,255,255,.1)",
                width: 1,
                type: "solid"
            },
        },
		
        axisTick: {
            show: false,
        },
		axisLabel:  {
                interval: 0,
                rotate:45,
                show: true,
                splitNumber: 15,
                textStyle: {
 					color: "rgba(255,255,255,.6)",
                    fontSize: '12',
                },
            },
    }],
    yAxis: [{
        type: 'value',
        axisLabel: {
           //formatter: '{value} %'
			show:true,
			 textStyle: {
 					color: "rgba(255,255,255,.6)",
                    fontSize: '12',
                },
        },
        axisTick: {
            show: false,
        },
        axisLine: {
            show: true,
            lineStyle: {
                color: "rgba(255,255,255,.1	)",
                width: 1,
                type: "solid"
            },
        },
        splitLine: {
            lineStyle: {
               color: "rgba(255,255,255,.1)",
            }
        }
    }],
    series: [
		{
       
        type: 'bar',
        data: lowestTemperatures,
        barWidth:'35%', //柱子宽度
       // barGap: 1, //柱子之间间距
        itemStyle: {
            normal: {
                color:'#27d08a',
                opacity: 1,
				barBorderRadius: 5,
            }
        }
    }
		
	]
};
      
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    }
function echarts_5(avg) {
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('echart5'));

    // 验证传入的数据
    if (!Array.isArray(avg)) {
        console.error('echarts_5: 传入的参数不是数组');
        return;
    }

    // 动态生成日期标签
    const dateLabels = Array.from({ length: avg.length }, (_, i) => {
        const day = i + 1;
        return day.toString().padStart(2, '0'); // 格式化为两位数，如 '01', '02', ..., '31'
    });

    // 使用所有传入的数据（不需要截取）
    const displayData = avg;

    var option = {
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'shadow'
            }
        },
        grid: {
            left: '0%',
            top: '10px',
            right: '0%',
            bottom: '2%',
            containLabel: true
        },
        xAxis: {
            type: 'category',
            data: dateLabels,
            axisLine: {
                show: true,
                lineStyle: {
                    color: "rgba(255,255,255,.1)",
                    width: 1,
                    type: "solid"
                },
            },
            axisTick: {
                show: false,
            },
            axisLabel: {
                interval: 0,
                show: true,
                textStyle: {
                    color: "rgba(255,255,255,.6)",
                    fontSize: '12',
                },
            },
        },
        yAxis: {
            type: 'value',
            axisLabel: {
                show: true,
                textStyle: {
                    color: "rgba(255,255,255,.6)",
                    fontSize: '12',
                },
            },
            axisTick: {
                show: false,
            },
            axisLine: {
                show: true,
                lineStyle: {
                    color: "rgba(255,255,255,.1)",
                    width: 1,
                    type: "solid"
                },
            },
            splitLine: {
                lineStyle: {
                    color: "rgba(255,255,255,.1)",
                }
            }
        },
        series: [{
            name: '平均温度',
            type: 'line',
            data: displayData,
            smooth: false,
            symbol: 'circle',
            symbolSize: 5,
            showSymbol: false,
            lineStyle: {
                normal: {
                    color: '#2f89cf',
                    width: 2
                }
            },
            areaStyle: {
                normal: {
                    color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
                        { offset: 0, color: 'rgba(47, 137, 207, 0.6)' },
                        { offset: 1, color: 'rgba(47, 137, 207, 0.1)' }
                    ])
                }
            },
            itemStyle: {
                normal: {
                    color: '#2f89cf',
                    borderColor: 'rgba(221, 220, 107, .1)',
                    borderWidth: 12
                }
            }
        }]
    };

    // 使用刚指定的配置项和数据显示图表。
    myChart.setOption(option);
    window.addEventListener("resize", function() {
        myChart.resize();
    });
}
	
function echarts_4(max,min) {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('echart4'));
        const dateLabels = Array.from({ length: max.length }, (_, i) => {
        const day = i + 1;
        return day.toString().padStart(2, '0'); // 格式化为两位数，如 '01', '02', ..., '31'
    });

    option = {
	    tooltip: {
        trigger: 'axis',
        axisPointer: {
            lineStyle: {
                color: '#dddc6b'
            }
        }
    },
		    legend: {
    top:'0%',
        data:['高温','低温'],
                textStyle: {
           color: 'rgba(255,255,255,.5)',
			fontSize:'12',
        }
    },
    grid: {
        left: '10',
		top: '30',
        right: '10',
        bottom: '10',
        containLabel: true
    },

    xAxis: [{
        type: 'category',
        boundaryGap: false,
axisLabel:  {
                textStyle: {
 					color: "rgba(255,255,255,.6)",
					fontSize:12,
                },
            },
        axisLine: {
			lineStyle: { 
				color: 'rgba(255,255,255,.2)'
			}

        },

   data: dateLabels
    }, {

        axisPointer: {show: false},
        axisLine: {  show: false},
        position: 'bottom',
        offset: 20,

       

    }],

    yAxis: [{
        type: 'value',
        axisTick: {show: false},
        axisLine: {
            lineStyle: {
                color: 'rgba(255,255,255,.1)'
            }
        },
       axisLabel:  {
                textStyle: {
 					color: "rgba(255,255,255,.6)",
					fontSize:12,
                },
            },

        splitLine: {
            lineStyle: {
                 color: 'rgba(255,255,255,.1)'
            }
        }
    }],
    series: [
		{
        name: '高温',
        type: 'line',
         smooth: true,
        symbol: 'circle',
        symbolSize: 5,
        showSymbol: false,
        lineStyle: {
			
            normal: {
				color: '#0184d5',
                width: 2
            }
        },
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(1, 132, 213, 0.4)'
                }, {
                    offset: 0.8,
                    color: 'rgba(1, 132, 213, 0.1)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
            }
        },
			itemStyle: {
			normal: {
				color: '#0184d5',
				borderColor: 'rgba(221, 220, 107, .1)',
				borderWidth: 12
			}
		},
        data:max

    }, 
{
        name: '低温',
        type: 'line',
        smooth: true,
        symbol: 'circle',
        symbolSize: 5,
        showSymbol: false,
        lineStyle: {
			
            normal: {
				color: '#00d887',
                width: 2
            }
        },
        areaStyle: {
            normal: {
                color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [{
                    offset: 0,
                    color: 'rgba(0, 216, 135, 0.4)'
                }, {
                    offset: 0.8,
                    color: 'rgba(0, 216, 135, 0.1)'
                }], false),
                shadowColor: 'rgba(0, 0, 0, 0.1)',
            }
        },
			itemStyle: {
			normal: {
				color: '#00d887',
				borderColor: 'rgba(221, 220, 107, .1)',
				borderWidth: 12
			}
		},
        data: min

    }, 
	
		 ]

};
      
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    }
function echarts_6() {
    // 初始化 echarts 实例
    var myChart = echarts.init(document.getElementById('echart6'));
    // 获取平均温度数据
    var temp = averageTemperatures;

    // 检查 temp 是否为 undefined 或者长度为 0
    if (!temp || temp.length === 0) {
        console.error('averageTemperatures 数组未正确初始化或为空');
        return;
    }

    // 城市名称数组
    var data = [
        '安庆市', '亳州市', '蚌埠市', '滁州市', '池州市',
        '阜阳市', '淮南市', '淮北市', '黄山市', '合肥市',
        '六安市', '马鞍山市', '宿州市', '铜陵市', '芜湖市',
        '宣城市', '砀山县', '广德市'
    ];

    // 生成散点图所需的数据格式
    var scatterData = data.map((name, index) => [index, temp[index], name]);

    // 配置散点图的选项
    var option = {
        color: [
            '#0f63d6', '#0f78d6', '#0f8cd6', '#0fa0d6', '#0fb4d6',
            '#0fc7d6', '#0fd9d6', '#0fe1d6', '#0fe9d6', '#0ff1d6',
            '#0ff8d6', '#0fffd6', '#0fffd7', '#0fffd8', '#0fffd9',
            '#0ffdda', '#0ffddb'
        ],
        tooltip: {
            show: true,
            formatter: function (params) {
                return params.data[2] + ': ' + params.data[1];
            }
        },
        xAxis: {
            type: 'value',
            axisLine: {
                lineStyle: {
                    color: 'rgba(255,255,255,.1)'
                }
            },
            axisTick: {
                show: false
            },
            axisLabel: {
                show: false
            }
        },
        yAxis: {
            type: 'value',
            axisLine: {
                lineStyle: {
                    color: 'rgba(255,255,255,.1)'
                }
            },
            axisTick: {
                show: false
            },
            axisLabel: {
                textStyle: {
                    color: 'rgba(255,255,255,.6)',
                    fontSize: 12
                }
            },
            splitLine: {
                lineStyle: {
                    color: 'rgba(255,255,255,.1)'
                }
            }
        },
        series: [
            {
                type: 'scatter',
                data: scatterData,
                symbolSize: 10,
                label: {
                    show: true,
                    position: 'top',
                    formatter: function (params) {
                        return params.data[2];
                    },
                    textStyle: {
                        color: 'rgba(255,255,255,.6)',
                        fontSize: 12
                    }
                },
                itemStyle: {
                    color: function (params) {
                        return option.color[params.dataIndex % option.color.length];
                    }
                }
            }
        ]
    };

    // 使用配置项显示图表
    myChart.setOption(option);

    // 窗口大小改变时重新调整图表大小
    window.addEventListener("resize", function () {
        myChart.resize();
    });
}




function echarts_31(datas) {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('fb1')); 
option = {
	    title: [{
        text: '温度分布',
        left: 'center',
        textStyle: {
            color: '#fff',
			fontSize:'16'
        }

    }],
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c} ({d}%)",
position:function(p){
            return [p[0] + 10, p[1] - 10];
        }
    },
    legend: {
        
top:'70%',
       itemWidth: 10,
        itemHeight: 10,
        data:['0℃以下','0-20℃','21-30℃','31-40℃','40℃以上'],
                textStyle: {
            color: 'rgba(255,255,255,.5)',
			fontSize:'12',
        }
    },
    series: [
        {
        	name:'温度分布',
            type:'pie',
			center: ['50%', '42%'],
            radius: ['40%', '60%'],
                  color: ['#065aab', '#066eab', '#0682ab', '#0696ab', '#06a0ab','#06b4ab','#06c8ab','#06dcab','#06f0ab'],	
            label: {show:false},
			labelLine: {show:false},
            data:datas
        }
    ]
};
      
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    }
function echarts_32(datas) {
        // 基于准备好的dom，初始化echarts实例
        var myChart = echarts.init(document.getElementById('fb2'));
option = {
   
	    title: [{
        text: '温度等级分布',
        left: 'center',
        textStyle: {
            color: '#fff',
			fontSize:'16'
        }

    }],
    tooltip: {
        trigger: 'item',
        formatter: "{a} <br/>{b}: {c} ({d}%)",
position:function(p){   //其中p为当前鼠标的位置
            return [p[0] + 10, p[1] - 10];
        }
    },
    legend: {
        
    top:'70%',
       itemWidth: 10,
        itemHeight: 10,
        data:['高温','正常','低温'],
                textStyle: {
           color: 'rgba(255,255,255,.5)',
			fontSize:'12',
        }
    },
    series: [
        {
        	name:'温度等级分布',
            type:'pie',
			center: ['50%', '42%'],
            radius: ['40%', '60%'],
            color: ['#065aab','#06a0ab','#06f0ab'],
            label: {show:false},
			labelLine: {show:false},
            data:datas
        }
    ]
};
      
        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
        window.addEventListener("resize",function(){
            myChart.resize();
        });
    }
function echarts_33(city) {
    // 从接口获取天气统计信息
    fetch(`http://127.0.0.1:5000/weather_stats?city=${encodeURIComponent(city)}`)
      .then(response => {
            if (!response.ok) {
                throw new Error('网络响应失败');
            }
            return response.json();
        })
      .then(data => {
            if (data.error) {
                alert(data.error);
                return;
            }

            // 将统计结果转换为适合 echarts 的数据格式
            var weatherData = Object.entries(data).map(([weather, count]) => ({
                value: count,
                name: weather
            }));

            // 更新图例数据
            var legendData = Object.keys(data);

            // 基于准备好的dom，初始化echarts实例
            var myChart = echarts.init(document.getElementById('fb3'));

            var option = {
                title: [
                    {
                        text: '天气分布',
                        left: 'center',
                        textStyle: {
                            color: '#fff',
                            fontSize: '16'
                        }
                    }
                ],
                tooltip: {
                    trigger: 'item',
                    formatter: "{a} <br/>{b}: {c} ({d}%)",
                    position: function (p) {
                        // 其中p为当前鼠标的位置
                        return [p[0] + 10, p[1] - 10];
                    }
                },
                legend: {
                    top: '70%',
                    itemWidth: 10,
                    itemHeight: 10,
                    data: legendData,
                    textStyle: {
                        color: 'rgba(255,255,255,.5)',
                        fontSize: '12'
                    }
                },
                series: [
                    {
                        name: '天气分布',
                        type: 'pie',
                        center: ['50%', '42%'],
                        radius: ['40%', '60%'],
                        color: [
                            '#065aab',
                            '#066eab',
                            '#0682ab',
                            '#0696ab',
                            '#06a0ab',
                            '#06b4ab',
                            '#06c8ab',
                            '#06dcab',
                            '#06f0ab'
                        ],
                        label: { show: false },
                        labelLine: { show: false },
                        data: weatherData
                    }
                ]
            };

            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
            window.addEventListener("resize", function () {
                myChart.resize();
            });
        })
      .catch(error => {
            console.error('请求天气数据时出错：', error);
            alert("获取天气数据失败，请稍后重试！");
        });
}


				
	
})



		
		
		


		









